#include <string.h>

#include <common/macro/build.h>
#include <common/macro/debug.h>
#include <common/datatype.h>
#include <common/datatypelist.h>

API_LIBLOCAL datatype_t *datatypelist[] = {
	&dt_string,
	&dt_int64,
	&dt_array,
	&dt_float64,
	NULL
};

/** 
* @brief Lookup a predicate in the datatype, by the predicate name.
* 
* @param datatype
* @param name
* 
* @return Predicate if found, NULL otherwise.
*/
API_LIBLOCAL predicate_t *datatype_predicate_lookup(datatype_t *datatype, const char *name) {
	int i;

	assert(datatype != NULL);

	for (i = 0; datatype->predicates[i].name != NULL; i++) {
		if (strcmp(datatype->predicates[i].name, name) == 0)
			return &datatype->predicates[i];
	}

	return NULL;
}

/** 
* @brief Lookup a datatype, by the datatype name.
* 
* @param name
* 
* @return Datatype if foudn, NULL otherwise.
*/
API_LIBLOCAL datatype_t *datatype_lookup(const char *name) {
	int i;
	
	assert(name != NULL);

	debugmsg("Looking up: '%s'\n", name);
	for (i = 0; datatypelist[i] != NULL; i++) {
		if (!strcmp(datatypelist[i]->name, name))
			return datatypelist[i];
	}

	return NULL;
}
